from PySide6.QtWidgets import QMenu,QFontDialog
from custom_plain_text_edit import PlainTextEdit

class FileMenu(QMenu):
    """文件菜单

    :param QMenu: PySide6 菜单类
    """
    pass

class EditMenu(QMenu):
    """编辑菜单

    :param QMenu: PySide6 菜单类
    """
    pass

class FormatMenu(QMenu):
    """格式菜单

    :param QMenu: PySide6 菜单类
    """
    def __init__(self):
        """初始化
        """
        super().__init__()
        self.setup_ui()

    def setup_ui(self):
        """设置菜单项
        """
        # 设置菜单标题
        self.setTitle("格式(&O)")

        # 添加自动换行 和 字体 行为
        self.__line_warp = self.addAction("自动换行(&W)")
        self.__font_dialog =  self.addAction("字体(&F)")

        # 设置自动换行 可勾选 且 默认勾选
        self.__line_warp.setCheckable(True)
        self.__line_warp.setChecked(True)

    def set_event_bind(self,plain_text_edit: PlainTextEdit):
        """设置事件绑定
        """
        self.__line_warp.triggered.connect(plain_text_edit.set_line_warp_mode)
        self.__font_dialog.triggered.connect(lambda: self.set_font(plain_text_edit))

    def set_font(self,plain_text_edit: PlainTextEdit):
        """显示字体对话框 然后设置字体
        """
        ok,font = QFontDialog.getFont()
        if ok:
            plain_text_edit.setFont(font)